package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.ClazzMapper;
import com.itheima.pojo.Clazz;
import com.itheima.pojo.Emp;
import com.itheima.pojo.PageBean;
import com.itheima.service.ClazzService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Service
public class ClazzServiceImpl implements ClazzService {

    private static final Logger log = LoggerFactory.getLogger(ClazzServiceImpl.class);
    @Autowired
    private ClazzMapper clazzMapper;

    @Override
    public PageBean getList(String name, LocalDate begin, LocalDate end,Integer page, Integer pageSize) {

        PageHelper.startPage(page,pageSize);
        Page<Clazz> list = clazzMapper.list(name,begin,end);
        return new PageBean(list.getTotal(),list.getResult());
    }

    @Override
    public List<Clazz> getAll() {
        List<Clazz> list = clazzMapper.getAll();
        return list;
    }

    @Override
    public void deleteById(Integer id) {
        clazzMapper.deleteById(id);
    }

    @Override
    public void save(Clazz clazz) {
        clazz.setCreateTime(LocalDateTime.now());
        clazz.setUpdateTime(LocalDateTime.now());
        clazzMapper.insert(clazz);
    }

    @Override
    public Clazz getById(Integer id) {
        Clazz clazz = clazzMapper.getInfo(id);
        return clazz;
    }

    @Override
    public void update(Clazz clazz) {
        clazz.setUpdateTime(LocalDateTime.now());
        clazzMapper.updateClazz(clazz);
    }
}
